import tkinter as tk

def triangle(d, h, unit):
    # 求三角形面积
    if unit == '1':
        s = d * h / 2
    elif unit == '2':
        d = d * 2.54
        h = h * 2.54
        s = d * h / 2
    window = tk.Tk()
    window.title('所求结果')
    window.geometry('400x120')
    var = tk.StringVar()

    label = tk.Label(window, text='底,高分别为'+str(d) +', '+str(h)+'厘米的三角形面积为'+str('%.3f'%s)+ '平方厘米',
                     bg='yellow', width=100, height=10)
    label.pack()

    print('\n底,高分别为', d, ',', h,'厘米的三角形面积为', '%.3f'%s, '平方厘米')

def rectangle(c, k, unit):
    # 求矩形面积
    if unit == '1':
        s = c * k
    elif unit == '2':
        c = c * 2.54
        k = k * 2.54
        s = c * k

    window = tk.Tk()
    window.title('所求结果')
    window.geometry('400x120')
    var = tk.StringVar()

    label = tk.Label(window, text='长,宽分别为' + str(c) + ', ' + str(k) + '厘米的矩形面积为' + str('%.3f' % s) + '平方厘米',
                     bg='yellow', width=100, height=10)
    label.pack()

    print('\n长,宽分别为',c , ',', k, '厘米的矩形面积为', '%.3f'%s, '平方厘米')

def circle(d, unit):
    # 求圆形面积
    pi = 3.1415926
    if unit == '1':
        s = d * d * pi / 4
    elif unit == '2':
        d = d * 2.54
        s = d * d * pi / 4

    window = tk.Tk()
    window.title('所求结果')
    window.geometry('400x120')
    var = tk.StringVar()

    label = tk.Label(window, text='直径为' + str(d) + '厘米的圆形面积为' + str('%.3f' % s) + '平方厘米',
                     bg='yellow', width=100, height=10)
    label.pack()

    print('\n直径为', d, '厘米的圆形面积为', '%.3f'%s, '平方厘米')